package com.hxl.aop.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hxl.aop.entity.UserEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping(("/hello"))
public class HelloController {

    @GetMapping(value = "/add")
    public String hello() {
        if (1 == 1) {
            throw new NullPointerException("空指针测试");
        }
        return "hello world";
    }

    @GetMapping(value = "/delete")
    public String delete() {
        if (1 == 1) {
            throw new RuntimeException("其它测试");
        }
        return "hello world";
    }


    public static void main(String[] args) throws JsonProcessingException {
        UserEntity userEntity = new UserEntity();
        userEntity.setUserId("1433223");
        userEntity.setName("黑小绿");
        userEntity.setMobile("15511067075");
        userEntity.setIdCard("412825200007170535");
        userEntity.setAge(20);
        userEntity.setSex("男");
        userEntity.setPassword("aass555666.");

        //通过jackson方式，将对象序列化成json字符串
        ObjectMapper objectMapper = new ObjectMapper();
        System.out.println(objectMapper.writeValueAsString(userEntity));

        List messages = Arrays.asList("a", "b", "c");
        Object[] objects = messages.toArray(new String[0]);
        System.out.println(objects);
    }
}